package container

import (
	"log"
	"reflect"
)

var container map[string]any = make(map[string]any)

// PushContainer 添加实例到容器
func PushContainer(bean any) {
	fullName := reflect.TypeOf(bean).Elem().String()
	if _, ok := container[fullName]; ok {
		log.Panicln("重复添加bean：", fullName)
	}
	container[fullName] = bean
}

// GetBeanContainer 从容器中获取bean
func GetBeanContainer(fullName string) (any, bool) {
	bean, ok := container[fullName]
	return bean, ok
}

// GetBeanFromContainer 从容器中获取bean
func GetBeanFromContainer(fullName string) any {
	bean, ok := container[fullName]
	if !ok {
		panic("不存在该bean，请检查！" + fullName)
	}
	return bean
}
